import {
	defineStore
} from 'pinia'
import {
	computed,
	ref
} from 'vue'

export default defineStore('token', () => {
	const token = ref(uni.getStorageSync('token') || '')

	// 设置 Token
	const setToken = (newToken) => {
		token.value = newToken
		uni.setStorageSync('token', newToken)
	}

	// 清除 Token
	const clearToken = () => {
		token.value = ''
		uni.removeStorageSync('token')

		console.log('内存中的 token:', token.value); // 应该是 ''
		console.log('Storage 中的 token:', uni.getStorageSync('token')); // 应该是 undefined

		// 确保没有其他代码干扰
		setTimeout(() => {
			console.log('5秒后再次检查 Storage:', uni.getStorageSync('token'));
		}, 5000);
	}

	return {
		token,
		setToken,
		clearToken
	}
})